#include "stm32f1xx_hal.h"
#include "hal_tlc5615.h"

void HAL_TLC5615_Init(void)
{
	__HAL_RCC_GPIOB_CLK_ENABLE();
	
	
	GPIO_InitTypeDef GPIO_InitStruct = {0}; 

	GPIO_InitStruct.Pin = DIN_PIN|SCLK_PIN|CS_PIN;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	//GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);
	
	SCLK_0;CS_1;DIN_0;
	
	
}


//时钟太快的话，需要加延时
void HAL_TLC5615_SetValue(uint16_t Value)
{
	uint8_t i = 0;
	
	Value <<= 6;
	
	SCLK_0;
	CS_0;
	
	
	for(i = 0; i < 12; i++)
	{
		if(Value&0x8000)
		{
			DIN_1;
		}
		
		else{
			DIN_0;
		}
		SCLK_1;
		
		Value <<= 1;
		SCLK_0;
		
	}
	
	SCLK_0;
	CS_1;
	
}




